import React, { PureComponent } from 'react'
import enhanceUserInfo1 from './hoc/enhanced_props'

// 定义组件：给一些需要特殊数据的组件，注入props
function enhanceUserInfo(Cpn) {
  class NewComponent extends PureComponent {
    constructor(props) {
      super(props)
      this.state = {
        userInfo: {
          name: 'coderwhy',
          level: 99,
        },
      }
    }

    render() {
      return <Cpn {...this.state.userInfo} {...this.props} />
    }
  }

  return NewComponent
}

function Home() {
  return <h1>Home</h1>
}

function HelloFirend() {
  return <h1>HelloFried</h1>
}

function Profile() {
  return <h1>Profile</h1>
}

const HomeHoc = enhanceUserInfo(Home)
const HelloFirendHoc = enhanceUserInfo1(HelloFirend)

export class app extends PureComponent {
  render() {
    return (
      <div>
        <Home />
        <HelloFirend />
        <Profile />

        <HomeHoc abc="abc" />
        <HelloFirendHoc />
      </div>
    )
  }
}

export default app
